﻿using RayD.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace RayD.Repository.Entites.SystemModule
{
    [Table("BASE_USER")]
    public class UserEntity
    {
        #region 实体成员
        /// <summary>
        /// 用户主键
        /// </summary>		
        [Key]
        [Column("B_USERID")]
        public string B_UserId { get; set; }
        /// <summary>
        /// 工号
        /// </summary>	
        [Column("B_ENCODE")]
        public string B_EnCode { get; set; }
        /// <summary>
        /// 账户
        /// </summary>	
        [Column("B_ACCOUNT")]
        public string B_Account { get; set; }
        /// <summary>
        /// 登录密码
        /// </summary>		
        [Column("B_PASSWORD")]
        public string B_Password { get; set; }
        /// <summary>
        /// 密码秘钥
        /// </summary>	
        [Column("B_SECRETKEY")]
        public string B_Secretkey { get; set; }
        /// <summary>
        /// 真实姓名
        /// </summary>
        [Column("B_REALNAME")]
        public string B_RealName { get; set; }
        /// <summary>
        /// 呢称
        /// </summary>	
        [Column("B_NICKNAME")]
        public string B_NickName { get; set; }
        /// <summary>
        /// 头像
        /// </summary>	
        [Column("B_HEADICON")]
        public string B_HeadIcon { get; set; }
        /// <summary>
        /// 简拼
        /// </summary>	
        [Column("B_SIMPLESPELLING")]
        public string B_SimpleSpelling { get; set; }
        /// <summary>
        /// 性别
        /// </summary>	
        [Column("B_GENDER")]
        public Gender? B_Gender { get; set; }
        /// <summary>
        /// 生日
        /// </summary>	
        [Column("B_BIRTHDAY")]
        public DateTime? B_Birthday { get; set; }
        /// <summary>
        /// 手机
        /// </summary>
        [Column("B_MOBILE")]
        public string B_Mobile { get; set; }
        /// <summary>
        /// 电话
        /// </summary>		
        [Column("B_TELEPHONE")]
        public string B_Telephone { get; set; }
        /// <summary>
        /// 电子邮件
        /// </summary>	
        [Column("B_EMAIL")]
        public string B_Email { get; set; }
        /// <summary>
        /// QQ号
        /// </summary>		
        [Column("B_OICQ")]
        public string B_OICQ { get; set; }
        /// <summary>
        /// 微信号
        /// </summary>	
        [Column("B_WECHAT")]
        public string B_WeChat { get; set; }
        /// <summary>
        /// MSN
        /// </summary>		
        [Column("B_MSN")]
        public string B_MSN { get; set; }
        /// <summary>
        /// 组织架构主键
        /// </summary>		
        [Column("B_MANAFRAMEID")]
        public string B_ManaframeId { get; set; }
        /// <summary>
        /// 部门主键
        /// </summary>		
        [Column("B_DEPARTMENTID")]
        public string B_DepartmentId { get; set; }
        /// <summary>
        /// 安全级别
        /// </summary>	
        [Column("B_SECURITYLEVEL")]
        public int? B_SecurityLevel { get; set; }
        /// <summary>
        /// 密码提示问题
        /// </summary>		
        [Column("B_QUESTION")]
        public string B_Question { get; set; }
        /// <summary>
        /// 密码提示答案
        /// </summary>	
        [Column("B_ANSWERQUESTION")]
        public string B_AnswerQuestion { get; set; }
        /// <summary>
        /// 排序码
        /// </summary>	
        [Column("B_SORTCODE")]
        public int? B_SortCode { get; set; }
        /// <summary>
        /// 有效标志
        /// </summary>	
        [Column("B_ENABLEDMARK")]
        public EnabledMark? B_EnabledMark { get; set; }
        /// <summary>
        /// 备注
        /// </summary>		
        [Column("B_DESCRIPTION")]
        public string B_Description { get; set; }
        /// <summary>
        /// 创建日期
        /// </summary>		
        [Column("B_CREATEDATE")]
        public DateTime? B_CreateDate { get; set; }
        /// <summary>
        /// 创建用户主键
        /// </summary>		
        [Column("B_CREATEUSERID")]
        public string B_CreateUserId { get; set; }
        /// <summary>
        /// 创建用户
        /// </summary>	
        [Column("B_CREATEUSERNAME")]
        public string B_CreateUserName { get; set; }
        /// <summary>
        /// 修改日期
        /// </summary>	
        [Column("B_MODIFYDATE")]
        public DateTime? B_ModifyDate { get; set; }
        /// <summary>
        /// 修改用户主键
        /// </summary>		
        [Column("B_MODIFYUSERID")]
        public string B_ModifyUserId { get; set; }
        /// <summary>
        /// 修改用户
        /// </summary>		
        [Column("B_MODIFYUSERNAME")]
        public string B_ModifyUserName { get; set; }
        #endregion

        #region 扩展操作
        /// <summary>
        /// 新增调用
        /// </summary>
        public void Create()
        {
            if (this.B_EnabledMark.IsEmpty())
            {
                this.B_EnabledMark = EnabledMark.Enabled;
            }
            this.B_UserId = Guid.NewGuid().ToString();
            this.B_CreateDate = DateTime.Now.ToCstTime();
            UserInfo userInfo = AuthenticationHelper.LoginUserInfo;
            this.B_CreateUserId = userInfo.userId;
            this.B_CreateUserName = userInfo.realName;
            this.B_Secretkey = Md5Helper.Encrypt(CommonHelper.CreateNo(), 16).ToLower();
            this.B_Password = Md5Helper.Encrypt(DESEncrypt.Encrypt(this.B_Password, this.B_Secretkey).ToLower(), 32).ToLower();
        }
        /// <summary>
        /// 编辑调用
        /// </summary>
        public void Modify()
        {
            if (this.B_DepartmentId.IsEmpty())
            {
                this.B_DepartmentId = "";
            }
            this.B_ModifyDate = DateTime.Now.ToCstTime();
            UserInfo userInfo = AuthenticationHelper.LoginUserInfo;
            this.B_ModifyUserId = userInfo.userId;
            this.B_ModifyUserName = userInfo.realName;
            this.B_Secretkey = null;
            this.B_Password = null;
        }
        #endregion
    }
}
